
let user = require('../../db/UserSchema')


let express = require('express');
let {createToken,vityToken}=require('../../utils/jwt')
let app = express();

module.exports = async (req, resp) => {
    let myid = req.body.username;

    await user.findOne({ username: myid }).then((data) => {
        if (!data) {
            resp.status(500).send("用户名不存在"+`<button><a href="/index/login">重新登录</a></button>`)
        } else {
            if (data.password != req.body.password) {
                resp.status(500).send("密码错误"+`<button><a href="/index/login">重新登录</a></button>`)
            } else {      
               
                // let usertoken=createToken({username:req.body.username,flag:true},20);

                // console.log("usertoken",usertoken);
                // console.log(req.body);
                req.session.username=req.body.username;
                resp.app.locals.username = req.body.username;
                // resp.render('./admin/welcomePage',{usertoken2:usertoken})
                resp.render('./admin/welcomePage');
            }
        }

    })

}